package com.backstage.web;

import cn.hutool.json.JSONString;
import com.alibaba.druid.support.json.JSONParser;
import com.alibaba.fastjson.JSON;
import com.backstage.pojo.dto.Message;
import com.backstage.pojo.entity.SysRole;
import com.backstage.pojo.entity.SysUser;
import com.backstage.pojo.entity.SysUserRole;
import com.backstage.pojo.vo.SysRoleSelectVo;
import com.backstage.pojo.vo.SysRoleVo;
import com.backstage.pojo.vo.SysUserRoleVo;
import com.backstage.pojo.vo.SysUserVo;
import com.backstage.service.SysRoleService;
import com.backstage.service.SysUserRoleService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class SysUserRoleController {
    @Autowired
    SysUserRoleService sysUserRoleService;
    @Autowired
    SysRoleService sysRoleService;

    @RequestMapping("/selectRoles")
    public List<SysUserRoleVo> selectRoles(long userId) {
        List<SysUserRoleVo> sysUserRoleVos = sysUserRoleService.selectUserRoleByUserId(userId);
        return sysUserRoleVos;
    }

    @RequestMapping("/selectNoRoles")
    public List<SysUserRoleVo> selectNoRoles(long userId) {
        List<SysUserRoleVo> sysUserRoleVos = sysUserRoleService.selectNoRoleByUserId(userId);
        return sysUserRoleVos;
    }

    @RequestMapping(value = "/updateRoles")
    public String updateRoles(String roles) {
        List<SysUserRoleVo> sysUserRoleVos = JSON.parseArray(roles, SysUserRoleVo.class);
        return sysUserRoleService.updateRoles(sysUserRoleVos);
    }

}
